package com.yupi.springbootinit.config;

import org.checkerframework.checker.units.qual.A;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author vvv
 * @date 2023-12-03 15 30
 * discription
 */
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(2, 4
                , 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(20), new ThreadFactory() {
            private LongAdder longAdder = new LongAdder();
            @Override
            public Thread newThread(@NotNull Runnable r) {
                Thread thread = new Thread(r);
                thread.setName("线程" + longAdder.intValue());
                longAdder.increment();
                return thread;
            }
        });
    }

}
